#include "login.h"
#include "ui_login.h"

Login::Login(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Login),
    newregisterface(new registerface),
    newLogin(new manage_Login)
{
    ui->setupUi(this);

    setWindowIcon(QIcon(":/img/icon.jpg"));

    setWindowTitle("天天考试系统");

    connect(newregisterface, &registerface::close, this, &Login::registerfaceClose);
    connect(newLogin, &manage_Login::close, this, &Login::manageLoginClose);
}

void Login::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Escape)
    {
        qDebug() << "ESC is pressed simultaneously.";
        escPressed = true;
    }
    else if (event->key() == Qt::Key_Up)
    {
        qDebug() << "up is pressed simultaneously.";
        upPressed = true;
    }

    // 检查是否两个键都被按下
    if (escPressed && upPressed)
    {
        qDebug() << "ESC and up are pressed simultaneously.";
        newLogin->show();
        this->hide();
        escPressed = false;
        upPressed = false;
    }

    // 调用基类的方法以确保其他行为不受影响
    QWidget::keyPressEvent(event);
}

void Login::keyReleaseEvent(QKeyEvent *event)
{
    // 更新按键状态
    if (event->key() == Qt::Key_Escape)
    {
        qDebug() << "ESC is released simultaneously.";
        escPressed = false;
    }
    else if (event->key() == Qt::Key_Up)
    {
        qDebug() << "up is released simultaneously.";
        upPressed = false;
    }

    // 调用基类的方法
    QWidget::keyReleaseEvent(event);
}

/* 点击登录按钮 */
void Login::on_loginBtn_clicked()
{

}

/* 点击注册按钮 */
void Login::on_registerBtn_clicked()
{
    newregisterface->show();
    this->hide();
}

/* 注册页面关闭 */
void Login::registerfaceClose()
{
    newregisterface->hide();
    this->show();
}

/* 管理员登录页面关闭 */
void Login::manageLoginClose()
{
    newLogin->hide();
    this->show();
}

Login::~Login()
{
    delete ui;
}
